package com.ftg.learn.pattern.prototype;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author kangjx
 * @createTime 2022/8/9
 */
public class PrototypeCache {

    private Map<Class,Shape> beanmap = new ConcurrentHashMap<>(2);

    /**
     * 初始化容器，里面存储你要用到的类
     */
    public void loadCache(){
        beanmap.put(Cicle.class,new Cicle());
        beanmap.put(Sequare.class,new Sequare());
    }

    /**
     * 是不是也是单例
     * @param c
     * @return
     */
    public Shape getBean(Class c) throws CloneNotSupportedException {
        Shape a = beanmap.get(c);
        Object clone = a.clone();
        return (Shape) clone;
    }


}
